import com.proalias.animation.tween.Tween;
/**
 * @author Alias Cummins
 */
class com.proalias.animation.tween.WholePixelTween extends Tween{
	
	public function WholePixelTween(target:Object,properties:Object,easing:String,duration:Number) {
		super(target,properties,easing,duration);
		execute = executeRealTime;
	}
	
	
	private function executeRealTime():Boolean{
		trace("Tween.executeRealTime()");
		var func:Function = $easingFunction;
		if ($startValues == undefined){
			$startValues = new Object();
			for (var i in $properties){
				$startValues[i] = $target[i];
			}
		}
		
		if ($time < $duration){
			for (var i in $properties){
				var b:Number = $startValues[i];
				var c = $properties[i] - b;
				var d = $duration;
				$target[i] = func($time, b, c, d);
			}
			$time++;
			return true;
		}else{
			for (var i in $properties){
				$target[i] = int($properties[i]);
			}
			execute = null;	
			return false;
		}
		
	}
	
	private function executePreCalc():Boolean{
		trace("Tween.executePreCalc()");
		if ($time < $duration){
			for (var i in $properties){
				$target[i] = int($preCalcObj[i][$time]);
			}
			$time++;
			return true;
		}else{
			for (var i in $properties){
				$target[i] = int($properties[i]);
			}
			return false;
		}
		return true;
	}
}